/**
 * 
 */
package leetCode;

/**
 * @author zhongfang
 *
 */
public class CanPlaceFlowers {
    public static boolean canPlaceFlowers(int[] flowerbed, int n) {
        int max=0;
        for (int i = 0; i < flowerbed.length; i++) {
        	if((i==0||flowerbed[i-1]==0)&&flowerbed[i]==0&&(i+1==flowerbed.length||flowerbed[i+1]==0)){
    			flowerbed[i]=1;
    			max++;
        	}
		}
        return  n<=max;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] n={1,0,0,0,1,0,0};
		System.out.println(canPlaceFlowers(n, 2));
	}

}
